package net.pimpas.web.jsf.page.controller;

import java.util.HashMap;
import java.util.Map;

import net.pimpas.core.visitor.BaseClassVisitor;
import net.pimpas.util.reflection.ReflectionUtil;

import org.apache.log4j.Logger;

public class PageControllerVisitor extends BaseClassVisitor {
	protected static final Map<String, Class<? extends PageController>> pages = new HashMap<String, Class<? extends PageController>>();
	private static Logger logger = Logger.getLogger(PageControllerVisitor.class);
	@SuppressWarnings("unchecked")
	@Override
	public void visitClass(Class arg0) {
		if(ReflectionUtil.checkAnnotationInClass(PageControl.class, arg0)) {
			PageControl ctrl = (PageControl) arg0.getAnnotation(PageControl.class);
			pages.put(ctrl.pageUri(), arg0);
			logger.info("[PageControllerVisitor]: Added PageController => PAGE NAME: "+ctrl.pageName()+", PAGE URI: "+ctrl.pageUri()+", CLASS: "+arg0);
		}
	}
	
	public static Map<String, Class<? extends PageController>> getPages( ) {
		return pages;
	}
}